package by.ostrovsky.webhousingsystem.controller.userrequest;

import java.util.LinkedList;
import java.util.List;

import org.apache.log4j.Logger;

import by.ostrovsky.webhousingsystem.controller.IUserController;
import by.ostrovsky.webhousingsystem.dao.DAOFactory;
import by.ostrovsky.webhousingsystem.dao.implementation.idao.IOperateDAO;
import by.ostrovsky.webhousingsystem.exception.CommonException;
import by.ostrovsky.webhousingsystem.exception.OperationErrorException;
import by.ostrovsky.webhousingsystem.hibernate.entity.UserRequest;

public class SendRequestController implements IUserController<UserRequest, Boolean>{
	private static Logger logger = Logger
			.getLogger(SendRequestController.class);

	@Override
	public Boolean send(UserRequest userRequest)
			throws CommonException {
		List<UserRequest> list = new LinkedList<UserRequest>();
		try {
			DAOFactory factory = DAOFactory.getDAOFactory(DAOFactory.MySQL);
			IOperateDAO<List<UserRequest>, Boolean> dao = factory
					.getHousingRequestDAO();

			list.add(userRequest);
			if (dao.create(list)) {
				return true;
			}
			return false;
		} catch (Exception e) {
			logger.error(e);
			throw new OperationErrorException();
		}
	}

	@Override
	public String login(UserRequest object) throws CommonException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public Boolean registrate(UserRequest object) throws CommonException {
		// TODO Auto-generated method stub
		return null;
	}
}
